/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: support x86 support mce notifier chain
 * Author: liwugui <liwugui1@huawei.com>
 * Create: 2023-09-07
 * Note: this file isn't compiled independently, it is included
 * in arch/x86/kernel/cpu/mce/core.c
 */

#ifdef CONFIG_RTOS_HAL_X86_MCE_NOTIFIER
static ATOMIC_NOTIFIER_HEAD(x86_mce_notifier_list);

int register_x86_mce_notifier(struct notifier_block *nb)
{
	if (!nb || !nb->notifier_call) {
		pr_err("register x86 mce notifier failed\n");
		return -EINVAL;
	}

	return atomic_notifier_chain_register(&x86_mce_notifier_list, nb);
}
EXPORT_SYMBOL_NS(register_x86_mce_notifier, HW_RTOS_NS);

int unregister_x86_mce_notifier(struct notifier_block *nb)
{
	if (!nb || !nb->notifier_call) {
		pr_err("unregister x86 mce notifier failed\n");
		return -EINVAL;
	}

	return atomic_notifier_chain_unregister(&x86_mce_notifier_list, nb);
}
EXPORT_SYMBOL_NS(unregister_x86_mce_notifier, HW_RTOS_NS);

static void notify_mce_call_chain(struct pt_regs *regs)
{
	atomic_notifier_call_chain(&x86_mce_notifier_list, 0, regs);
}
#endif
